<template>
  <div class="change-button" @click="handleChange" :class="`button-${active}`">
    <div class="button-input">
      {{ typeObj[type][active] }}
    </div>
  </div>
</template>

<script>
export default {
  props: {
    type: {
      default: "lon",
    },
    value: {
      default: true,
    },
  },
  computed: {
    active: {
      get() {
        return this.value ? "left" : "right";
      },
      set(val) {
        this.$emit("input", val === "left");
      },
    },
  },
  data() {
    return {
      typeObj: {
        lon: {
          left: "E",
          right: "W",
        },
        lat: {
          left: "N",
          right: "S",
        },
      },
    };
  },
  methods: {
    handleChange() {
      this.active = this.active === "left" ? "right" : "left";
    },
  },
};
</script>

<style scoped lang="scss">
.change-button {
  width: 44px;
  height: 22px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f6f6f6;
  overflow: hidden;
  display: flex;
  cursor: pointer;
  .button-input {
    color: #fff;
    background-color: #2770d4;
    width: 50%;
    text-align: center;
    font-size: 12px;
    line-height: 20px;
    user-select: none;
  }
}
.button-left {
  justify-content: left;
}
.button-right {
  justify-content: right;
}
</style>
